/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
		package menu;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import model.Student;
import dao.StudentDao;
public class Delet_Menu {
	Student delet_student;
	JFrame delet_menu;
	JPanel p1,p2;
	JLabel l1;
	JTextField text;
	JTextArea show;
	JButton delet_ok,delet_find,delet_cancel;
	
	public void student_delet(){
		delet_menu = new JFrame("学生信息删除");
		p1 = new JPanel();
		p2 = new JPanel();
		l1 = new JLabel("学号：");
		text = new JTextField(16);
		show = new JTextArea(100,100);
		delet_ok = new JButton("删除");
		delet_find = new JButton("搜索");
		delet_cancel = new JButton("取消");
		delet_ok.setEnabled(false);
		delet_cancel.addActionListener(new Monitor2());
		delet_find.addActionListener(new Monitor2());
		delet_ok.addActionListener(new Monitor2());
		delet_menu.add(p1,BorderLayout.NORTH);
		delet_menu.add(show,BorderLayout.CENTER);
		delet_menu.add(p2,BorderLayout.SOUTH);
		p1.add(l1);
		p1.add(text);
		p2.add(delet_find);
		p2.add(delet_ok);
		p2.add(delet_cancel);
		delet_menu.setBounds(400,200,400,400);
		delet_menu.setVisible(true);
	}
	
	private class Monitor2 implements ActionListener{
    	public void actionPerformed(ActionEvent e) {
			if(e.getActionCommand().equals("取消")){
				delet_menu.setVisible(false); 
				new Son_menu().studentmenu();
				}
			if(e.getActionCommand().equals("搜索")){
				delet_student = new StudentDao().findOne(Integer.parseInt(text.getText()));
				if(delet_student.getName()!= null)
					{
					String str = "找到学生  姓名："+delet_student.getName()+"  学号："+delet_student.getId()+" ";
					show.setText("");
					show.insert(str, 1);
					delet_ok.setEnabled(true);
					}
				else{
					show.setText("");
					show.insert("学生信息未找到", 1);}
				}
				if(e.getActionCommand().equals("删除")){
					new StudentDao().deleteInfo(delet_student);
					show.setText("");
					show.insert("学生信息已删除", 1);
					}
    	}
	}
	
	public static void main(String args[]){
		new Delet_Menu().student_delet();
	}
}

